<?php

namespace App\Http\Middleware;

use Closure;

class LoginLog
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        $username = $request->get('username');
        if(auth()->check()){
            \Log::info('login', ['username' => $username, 'ip' => $request->ip(), 'logintime' => date("H:i:s", $request->server()['REQUEST_TIME']),'result'=>'success']);
        }else{
            \Log::info('login', ['username' => $username, 'ip' => $request->ip(), 'logintime' => date("H:i:s", $request->server()['REQUEST_TIME']),'result'=>'fail']);
        }
        return $response;
    }
}
